﻿@model IEnumerable<RBS.Core.Model.SYS_DictInfo>

@{
    ViewBag.Title = "数据字典";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<!--导航栏-->
<div class="location">
    <a href="javascript:history.back(-1);" class="back"><i></i><span>返回上一页</span></a>
    <a href="@Url.Action("Main","Home")" class="home"><i></i><span>首页</span></a>
    <i class="arrow"></i>
      <a href="@Url.Action("DictInfoIndex","Sys")" ><span>数据字典</span></a>
    <i class="arrow"></i>
    <span>角色列表</span>
</div>
<!--/导航栏-->
<div style="float: left; width: 25%; padding-top: 15px;">
    <ul id="tt" class="easyui-tree" data-options="url:'../tools/DicInfoTree.ashx?action=dicinfotree',method:'get',animate:true"></ul>

    <script>
        $(window).resize(function(){  
            $('#tbDicInfoList').datagrid('resize');  
        });   
        var pid = 0;
        function expandTo() {
            var node = $('#tt').tree('find', 113);
            $('#tt').tree('expandTo', node.target).tree('select', node.target);
        }
        function getSelected() {
            var node = $('#tt').tree('getSelected');
            if (node) {
                var s = node.text;
                if (node.attributes) {
                    s += "," + node.attributes.p1 + "," + node.attributes.p2;
                }
                alert(s);
            }
        }
        $('#tt').tree({
            onClick: function (node) { 
                treeLoad(node.id);
                pid = node.id;
            }
        });
        /*Grid begion*/ 
        $(document).ready(function () {
            pid = @ViewBag.dicId; 
            treeLoad(pid);
            $("#dicinfoAdd").click(function () { 
                location.href = "@Url.Action("DictInfoCreate")?parentid=" + pid;
            });
        }); 
        function treeLoad(dicParentId) { 
            $('#tbDicInfoList').datagrid({
                url: 'DicInfoList?parentid=' + dicParentId,
                idField: 'DictID',
                fitColumns: true,
                minwidth: 300, 
                height: 280,
                columns: [[
                    { title: '名 称', field: 'DictName', align:'center',width:$(this).width() * 0.8},
                    { field: 'DictCode', title: '编 码',  align: 'center' },
                    { field: 'Sequence', title: '排 序', formatter: updateSequence },
                    { title: '操 作', field: 'DictID', formatter: formatProgress}
                ]]
               
            });
        } 
        function formatProgress(value) {
           
            if (value) { 
                var editurl = '@Url.Action("DictInfoEdit")' + "?id=" + value; 
                var deleteurl = '@Url.Action("DictInfoEdit")' + "?id=" + value + "&action=@RBS.Common.RBSEnums.ActionEnum.Delete"; 
                var addchildurl = '@Url.Action("DictInfoCreate")' + "?parentid=" + value;   
                var s = '&nbsp;<a href="' + editurl + '">编辑</a>&nbsp;|&nbsp;' +
                    '<a href="#" onclick="DelDictInfoChild(' + value + ')">删除</a>&nbsp;|&nbsp;' +
                    '<a href="' + addchildurl + '">添加字典项</a>&nbsp;';

                return s;
            } else {
                return '';
            }
        }
        function DelDictInfoChild(id) { 
            $.dialog.confirm("删除当前数据字典，会删除其子集<br/>删除后不可恢复，确认删除吗？", function () {
                $.ajax({
                    type: 'post', cache: false, dataType: 'json',
                    url: '@Url.Action("DictInfoDelete")',
                    data: [
                        { name: 'action', value: 'del' },
                        { name: 'ID', value: id }
                    ],
                    success: function (data) {
                        if (data.IsSuccess) {
                            loadPage(data.Data); 
                        }
                        else {
                         
                            $.dialog.alert(data.Msg);
                        }
                    }
                });
            });
            return false;
            
        }
        //排序
        var editingId;
        function updateSequence(value) {
           
            if (value) { 
                var s = '<input type="text"   onblur="UpdateSeq(this.value)"  value="' + value + '"  style="width:40px"   />';
                return s;
            } else {
                return '';
            }
        }

        function UpdateSeq(seq) {
            var row = $('#tbDicInfoList').datagrid('getSelected');
            if (!row) {
                return false;
            }
            $.ajax({
                type: 'post', cache: false, dataType: 'json',
                url: '../Controller/CategoryHandler.ashx',
                data: [
                    { name: 'action', value: 'sequence' },
                    { name: 'ID', value: row.ID },
                    { name: 'SEQ', value: seq }
                ],
                success: function (result) {
                    // alert(result);
                    if (!result) {
                        return;
                    } else {
                        treeLoad();
                    }
                },
                error: function () {
                    return;
                }
            });
        }
    /*grid End*/
    </script>
</div>
<div style="float: right; width: 75%">
    <!--工具栏-->
    <div class="toolbar-wrap">
        <div id="floatHead" class="toolbar">
            <div class="l-list">
                <ul class="icon-list">
                    <li><a class="add" href="#" id="dicinfoAdd"><i></i><span>新增</span></a> 
                    </li> 
                </ul>
            </div> 
        </div>
    </div>
    <!--/工具栏-->
    <table id="tbDicInfoList" class="ltable" ></table> 
</div>
